<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="db.tables.DBWorkTable"%>
<%@page import="db.DBMain"%>
<%@page import="html.RequestParser"%>
<%@page import="db.tables.DBTypeTable"%>
<%@page import="db.tables.reference.DBWorkAtTable"%>
<%@page import="java.sql.Date"%>
<%String file="./index.jsp?"+Constant.CONTENT+"="+Constant.work,method="get"; %>
<%RequestParser.send_action_file=file;
RequestParser.send_method=method;%>
<%@include file="town.jsp" %>
<script type="text/javascript">

<%
Long type_id_temp=DBMain.getTypeTable().selectLong(DBTypeTable.TYPE_ID_COL,DBTypeTable.TYPE_NAME_COL,Constant.Type.WORK_POSITION);
session.setAttribute(Constant.Content.TYPE,type_id_temp);

RequestParser workParser=new RequestParser(request,file,method);
workParser.isAdmin(admin);
workParser.setAdd(Constant.Content.ADD_WORK);
workParser.setContent(Constant.Content.WORK);
workParser.setSubmit(Constant.Content.SUBMIT_WORK);
workParser.setDelete(Constant.Content.DELETE_WORK);
workParser.setInput(new String[]{Constant.Content.INPUT_WORK,Constant.Content.TOWN});
workParser.setInsert_columns(new String[]{DBWorkTable.WORK_NAME_COL,DBWorkTable.TOWN_ID_COL});
workParser.setDisplay_columns(new String[]{DBWorkTable.WORK_ID_COL,DBWorkTable.WORK_NAME_COL});
workParser.setPk_column(DBWorkTable.WORK_ID_COL);
workParser.setTable(DBMain.getWorkTable());
workParser.setFk_column(DBWorkTable.TOWN_ID_COL);
workParser.setFk_id(town_id);
workParser.process();

RequestParser workAtParser=new RequestParser(request,file,method);
workAtParser.isAdmin(admin);
workAtParser.setAdd(Constant.Content.ADD_AT_WORK);
workAtParser.setContent(Constant.Content.AT_WORK);
workAtParser.setSubmit(Constant.Content.SUBMIT_AT_WORK);
workAtParser.setDelete(Constant.Content.DELETE_AT_WORK);
workAtParser.setInput(new String[]{Constant.Content.WORK,Constant.Content.CATEGORY,Constant.Content.INPUT_AT_WORK_DIVISION,Constant.Content.INPUT_AT_WORK_START,Constant.Content.INPUT_AT_WORK_END});
workAtParser.setInsert_columns(new String[]{DBWorkAtTable.USER_ID_COL,DBWorkAtTable.WORK_ID_COL,DBWorkAtTable.CATEGORY_ID_COL,DBWorkAtTable.ADD_INFO_COL,DBWorkAtTable.START_DATE_COL,DBWorkAtTable.END_DATE_COL});
workAtParser.setDisplay_columns(new String[]{DBWorkAtTable.WORK_AT_ID_COL,DBWorkAtTable.ADD_INFO_COL,DBWorkAtTable.START_DATE_COL,DBWorkAtTable.END_DATE_COL});
workAtParser.setPk_column(DBWorkAtTable.WORK_AT_ID_COL);
workAtParser.setTable(DBMain.getWorkAtTable());
workAtParser.setFk_column(DBWorkAtTable.USER_ID_COL);
workAtParser.setFk_id(user_id);
workAtParser.setPk_id(RequestParser.getLongFromParameter(request, workAtParser.getContent()));

	if(admin) {
		if (request.getParameter(workAtParser.getSubmit()) != null) {
			if (RequestParser.areAllParametersNotNull(request, workAtParser.getInput())) {
				Object[] result = new Object[workAtParser.getInsert_columns().length];
				//DBWorkAtTable.USER_ID_COL 
				result[0]=user_id;
				//DBWorkAtTable.WORK_ID_COL
				result[1]=Long.parseLong(request.getParameter(Constant.Content.WORK));
				//DBWorkAtTable.CATEGORY_ID_COL,
				result[2]=Long.parseLong(request.getParameter(Constant.Content.CATEGORY));
				//DBWorkAtTable.ADD_INFO_COL,
				result[3]=request.getParameter(Constant.Content.INPUT_AT_WORK_DIVISION);
				//DBWorkAtTable.START_DATE_COL,
				result[4]=Date.valueOf(request.getParameter(Constant.Content.INPUT_AT_WORK_START));
				//DBWorkAtTable.END_DATE_COL
				String t=request.getParameter(Constant.Content.INPUT_AT_WORK_END);
				if(t!=null&&!t.equals(""))
					result[5]=Date.valueOf(t);
				else result[5]=null;
				workAtParser.setPk_id(workAtParser.getTable().insertGetPK(workAtParser.getInsert_columns(), result));
			} else if (RequestParser.areSomeParametersNotNull(request, workAtParser.getInput())) {
				// Error output because only one parameter is set -
				// needed are both!
			}
		}
	}
	if(admin) {
		if (request.getParameter(workAtParser.getDelete()) != null && workAtParser.getPk_id() != null) {
			workAtParser.getTable().delete(workAtParser.getPk_column(), workAtParser.getPk_id());
		}
	}

	workAtParser.setArray(workAtParser.getTable().getSelect(workAtParser.getDisplay_columns(), new String[]{workAtParser.getFk_column()}, new Object[]{workAtParser.getFk_id()}));
%>
//
--></script>
<form name="<%=workParser.getContent() %>" action="<%=workParser.getSend_action_file() %>" method="<%=workParser.getSend_method()%>">
	<select name="<%=Constant.Content.WORK %>" onchange="submit()">
		<%
			workParser.printOptionList(out);
		%>
	</select>
<%@include file="category_only.jsp" %>
          <table width="38%" border="0">
       <tr> 
         <td width="17%">Abteilung:</td>
         <td width="83%">
           <input type="text" name="<%=Constant.Content.INPUT_AT_WORK_DIVISION%>">
         </td>
       </tr>
       <tr> 
         <td width="17%">Beginn:</td>
         <td width="83%">
           <input type="text" name="<%=Constant.Content.INPUT_AT_WORK_START%>" size="11" value="">
		<a href="javascript: void(0);" onmouseover="if (timeoutId) clearTimeout(timeoutId);window.status='Show Calendar';return true;" 
		onmouseout="if (timeoutDelay) calendarTimeout();window.status='';" onclick="g_Calendar.show(event,'<%=workParser.getContent() %>.<%=Constant.Content.INPUT_AT_WORK_START%>',true,'yyyy-mm-dd'); return false;">
		<img src="../images/calendar.gif" name="imgCalendar" width="34" height="21" border="0" alt=""></a>
         </td>
             <tr> 
         <td width="17%">Ende: </td>
         <td width="83%">
           <input type="text" name="<%=Constant.Content.INPUT_AT_WORK_END%>" size="11" value="">
		<a href="javascript: void(0);" onmouseover="if (timeoutId) clearTimeout(timeoutId);window.status='Show Calendar';return true;" 
		onmouseout="if (timeoutDelay) calendarTimeout();window.status='';" onclick="g_Calendar.show(event,'<%=workParser.getContent() %>.<%=Constant.Content.INPUT_AT_WORK_END%>',true,'yyyy-mm-dd'); return false;">
		<img src="../images/calendar.gif" name="imgCalendar" width="34" height="21" border="0" alt=""></a>
         </td>
             <tr>
         <td width="17%">
         	<input type="hidden" name="<%=Constant.Content.CATEGORY %>" value="<%=categoryParser.getPk_id() %>"/>
         	<input type="hidden" name="<%=workParser.getContent() %>" value="<%=workParser.getPk_id()%>"/>
         	<input type="hidden" name="<%=Constant.Content.COUNTRY %>" value="<%=country_id %>"/>
			<input type="hidden" name="<%=Constant.Content.TOWN %>" value="<%=town_id %>"/> 
           <input type="submit" name="<%=Constant.Content.SUBMIT_AT_WORK %>" value="Speichern">
         </td>
         <td width="83%">
           <input type="reset" name="zuruecksetzen" value="Zur&uuml;cksetzen">
         </td>
     </table>
</form>